package com.llmcu.msb.architect.concurrent.basic;

import java.util.concurrent.TimeUnit;

/**
 * 感受interrupt()与interrupted()
 *
 * @author liuling
 * @date 2024/9/17 18:29
 */
public class InterruptAndInterrupted {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            while (true) {
                // 等号只会打印一次
                if (Thread.interrupted()) {
                    System.out.println("========================");
                }
            }
        });
        thread.start();
        TimeUnit.SECONDS.sleep(2);
        thread.interrupt();

    }
}
